from app.config import config
from flask import Flask
from .views import config_blueprint
import logging
import datetime
d=str(datetime.datetime.now()).split(' ')[0]
logger = logging.getLogger(__name__)
logger.setLevel(level = logging.INFO)
# handler = logging.FileHandler(f"/home/hhy/qijia/{d}.txt")
handler = logging.FileHandler(f"jys.log")
handler.setLevel(logging.INFO)
fmt = "%(asctime)-15s %(levelname)s %(filename)s %(lineno)d %(process)d %(message)s"
datefmt = "%a %d %b %Y %H:%M:%S"
formatter = logging.Formatter(fmt, datefmt)
handler.setFormatter(formatter)





# 封装创建app的函数
def create_app(config_name):
    # 创建flask实例对象
    app = Flask(__name__)
    # 初始化
    app.config.from_object(config.get(config_name, 'default'))
    # 执行额外的初始化操作
    config[config_name].init_app(app)
    # 注册蓝本
    config_blueprint(app)
    #日志记录
    app.logger.addHandler(handler)
    #扩展文件打包
    # 返回生成的app
    return app